home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 21 / Mac Magazin and MacEasy Magazine CD - Issue 21.iso / Wissenschaft & Technik / yorick12vr1-fpu folder / include / show.i < prev    next >
Text File  |  1995-07-26  |  4KB  |  126 lines

  1. /*
  2.    SHOW.I
  3.    $Id: show.i,v 1.1 1993/08/27 18:50:06 munro Exp $
  4.  */
  5. /*    Copyright (c) 1994.  The Regents of the University of California.
  6.                     All rights reserved.  */
  7.  
  8. func raw_show(f, pat)
  9. /* DOCUMENT raw_show, f
  10.          or raw_show, f, pat
  11.          or raw_show, f, 1
  12.      prints a summary of the variables contained in binary file F.
  13.      If there are too many variables, use the second form to select
  14.      only those variables whose first few characters match PAT.
  15.      In the third form, continues the previous show command where it
  16.      left off -- this may be necessary for files with large numbers of
  17.      variables.
  18.      The variables are printed in alphabetical order down the columns.
  19.      The print function can be used to obtain other information about F.
  20.    SEE ALSO: openb, jt, jc
  21.  */
  22. {
  23.   /* NOTE-- codger confused if extern first on line */
  24.   /* state variables for show function */  extern _show_more, _show_pat;
  25.   if (typeof(pat)=="string") {
  26.     _show_pat= pat;
  27.     _show_more= array(0, 1:2);
  28.   } else if (!pat || is_void(_show_pat) || is_void(_show_more)) {
  29.     _show_pat= string(0);
  30.     _show_more= array(0, 1:2);
  31.   }
  32.  
  33.   both= get_vars(f);
  34.  
  35.   npass= both(2)? 2 : 1;
  36.   for (i=1 ; i<=npass ; i++) {
  37.     vars= *both(i);
  38.  
  39.     /* apply pattern matching if requested */
  40.     if (strlen(_show_pat)) {
  41.       vars= vars(where(strmatch(strpart(vars,1:strlen(_show_pat)),
  42.                 _show_pat)));
  43.       if (numberof(vars)) {
  44.     keep= array(string, 1:numberof(vars) /* be sure origin is 1 */);
  45.     keep(:)= vars;
  46.     vars= keep;
  47.       }
  48.     }
  49.  
  50.     /* quit if nothing to do */
  51.     n= numberof(vars);
  52.     if (!n || (_show_more(i) && _show_more(i)>=n)) {
  53.       if (i==1) {
  54.     if (strlen(_show_pat))
  55.       write, "<no"+(_show_more(i)?" more":"")+
  56.         " non-record variables begin with "+_show_pat+">"
  57.     else
  58.       write, "<no"+(_show_more(i)?" more":"")+
  59.         " non-record variables>";
  60.       } else {
  61.     write, "<no"+(_show_more(i)?" more":"")+
  62.         " record variables begin with "+_show_pat+">"
  63.       }
  64.       continue;
  65.     }
  66.  
  67.     /* put the list into alphabetical order, and make sure that both
  68.        the variable list and the length of each name are reasonable */
  69.     vars= vars(sort(vars));
  70.     if (_show_more(i)) {
  71.       n-= _show_more(i);
  72.       keep= array(string, 1:n /* be sure origin is 1 */);
  73.       keep(:)= vars(_show_more(i)+1:);
  74.       vars= keep;
  75.     }
  76.     if (n>64) {
  77.       keep= array(string, 1:65 /* be sure origin is 1 */);
  78.       keep(1:64)= vars(1:64);
  79.       keep(65)= "<<MORE>>";
  80.       vars= keep;
  81.     }
  82.     longest= max(strlen(vars));
  83.     if (longest>72) {
  84.       keep= where(strlen(vars)>72);
  85.       vars(keep)= strpart(vars(keep), 1:69)+"...";
  86.       longest= 72;
  87.     }
  88.  
  89.     /* split the vars into columns reading alphabetically down the
  90.        columns */
  91.     ncols= 78/(longest+5);
  92.     nrows= 1+(numberof(vars)-1)/ncols;
  93.     keep= array(string, 1:nrows, 1:ncols /* be sure origin is 1 */);
  94.     keep(1:numberof(vars))= vars;
  95.     vars= transpose(keep);
  96.  
  97.     /* list variables */
  98.     if (i==1) write, print(n)(1)+(_show_more(1)?" more":"")+
  99.                      " non-record variables:"
  100.     else write, print(n)(1)+(_show_more(2)?" more":"")+
  101.                      " record variables:"
  102.     write, format="     %"+print(longest)(1)+"s", linesize=78, vars;
  103.     write, "";  /* adds newline at end */
  104.     _show_more(i)+= 64;
  105.   }
  106.  
  107.   if (npass>1 && is_void(pat)) {
  108.     recs= print(f);
  109.     recs= recs(where(strmatch(recs, "  Current record")));
  110.     if (!is_void(recs)) write, recs;
  111.     times= get_times(f);
  112.     if (!is_void(times)) {
  113.       write, format="   Ranging from time= %e to time= %e\n",\
  114.     min(times), max(times);
  115.     } else {
  116.       ncycs= get_ncycs(f);
  117.       if (!is_void(ncycs)) {
  118.     write, format="   Ranging from ncyc= %d to ncyc= %d\n",\
  119.       min(ncycs), max(ncycs);
  120.       }
  121.     }
  122.   }
  123. }
  124.  
  125. /*--------------------------------------------------------------------------*/
  126.